﻿using System;
using UnityEngine;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;
using TMPro;

public class TextMeshProUGUIBinder : BinderBase
{
    public enum AttributeType : int
    {
        text,
        color,
    }

    private TextMeshProUGUI _target;

    public TextMeshProUGUI Target => _target;

    public TextMeshProUGUIBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public TextMeshProUGUIBinder()
    {
        
    }

    public override void Dispose()
    {
        _target = null;
        base.Dispose();
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<TextMeshProUGUI>();
        _active = _target != null;
    }

    public override void SetString(string value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.text:
                _target.text = value;
            break;
            default:
            break;
        }
        base.SetString(value);
    }
    
    public override void SetColor(Color value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.color:
                _target.color = value;
            break;
            default:
            break;
        }
        base.SetColor(value);
    }
    

}
